package Collecion;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class collecionText {
    public static void main(String[] args) {
        List<String> list = new ArrayList();
        //list.add()可以添加任何类型
        list.add("张三");
        list.add("123");
        list.add("true");

        //当list 变成list<类型>是可以进行限定
        list.add("张三");
        for (String s:list) {
            System.out.println("姓名："+s);
        }
        System.out.println(list);

    }

    private static void text2() {
        List list =  new ArrayList();
        list.add("张本");
        list.add("张二本");
        list.add("张三本");
        list.add(1,"张一本");
        for (int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        //1 删除张二本 2修改张一本为张二本判断集合是否有李一本
        list.remove("张二本");
        list.set(1,"李一本");
        System.out.println(list);
        System.out.println(list.contains("李一本"));
        //用索引判断
        int index = list.indexOf("李一本");
        System.out.printf("index = "+index);
    }

    private static void text1() {
        ArrayList list= new ArrayList();
        Collection collection = new ArrayList();
        //添加
        collection.add("张三");
        collection.add("李四");
        collection.add("李四");
        System.out.println(collection);
        //删除
        collection.remove("李四");
        System.out.println(collection);
        //判断是否包含
        System.out.println(collection.contains("张三"));
        Collection c2 = new ArrayList();
        c2.add(1);
        c2.add(2);

        collection.add(c2);//添加对象
        collection.addAll(c2);//添加c2元素
        collection.remove(c2);//删除c2的元素
        System.out.println(collection);
    }
}

